﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace WeProjects.Helps
{
    public static class Extensions
    {
        public static MvcHtmlString MenuLink(this HtmlHelper htmlHelper,
                                           string linkText, string actionName, string controllerName, object routeValues=null)
        {

            string currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
            string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller");

            if (controllerName == currentController ||
                currentController.RelatedControllers().Contains(controllerName))
            {
                return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, new { @class = "active" });
            }

            return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, null);


        }
        private static List<string> RelatedControllers(this string currentController)
        {
            List<string> controllers = new List<string>();
            switch (currentController)
            {
                case "ExpertGroup":
                case "ExpertJudge":
                    controllers = new List<string> { "ExpertGroup", "ExpertJudge" };
                    break;
                case "Rule":
                case "Subject":
                    controllers = new List<string> { "Rule", "Subject" };
                    break;
            }
            return controllers;

        }

        public static string StripHtmlTags(this string post)
        {
            if (post == null)
            {
                return "";
            }
            else
            {
                return Regex.Replace(post, @"<[^>]*>", String.Empty);
            }
        }
    }
}